<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
use app\models\UploadForm;
use yii\web\UploadedFile;
use app\models\Dev_goods;
use yii\data\Pagination;
class GoodController extends Controller
{
    
       public function actionUpload()
    {
        $model = new UploadForm();

        if (Yii::$app->request->isPost) {
            $model->path = UploadedFile::getInstance($model, 'path');
            if ($model->upload()) {
                // 文件上传成功
                return;
            }
        }

        return $this->render('upload', ['model' => $model]);
    }
   public function actionAdd(){
   	return $this->render('add');
   }   

   public function actionAdd_do()   
 	{ 
	 $data=yii::$app->request->post();
	 // print_r($data);
	 $model=new Dev_goods();
	 $model->name=$data['name'];
	 $model->price=$data['price'];
	 $model->stock=$data['stock'];
	 $model->stock=$data['status'];
	 $res=$model->add();
	    if($res)
	    {
	      return $this->redirect(['goods/show']);
		 }else{
		 	return $this->redirect(['goods/show']);
		 }

	}  
    public function actionShow(){
    	$query = Dev_goods::find();
    $countQuery = clone $query;
    $pages = new Pagination(['totalCount' => $countQuery->count(),'defaultPageSize' => 3]);
      $models = $query->offset($pages->offset)
        ->limit($pages->limit)
        ->all();

    return $this->render('show', [
         'models' => $models,
         'pages' => $pages,
    ]);
   }
   public function del(){
   	 $id=$_GET['id'];
   	  $model=new Dev_goods();
   	  $del=$model->del($id);
      if($del){
       return $this->redirect(['show']);
      }
   }

     public function saves(){
   	 $id=$_GET['id'];
   	  $model=new Dev_goods();
   	  $sav=$model->saves($id);
   	  if($sav){
       return $this->redirect(['show']);
      }
   }
   
}

?>